<?php

class Quad_Router_Scrub extends Quad_MagicProperties {
	
	protected $_route;
	protected $_controllerName;
	protected $_actionName;
	protected $_data;
	protected $_post;
	protected $_cookie;
	
	public function __construct($route) {
		$this->_route = $route;
		$this->_controllerName = $this->_route->getControllerName();
		$this->_actionName = $this->_route->getActionName();
		$this->_data = $this->_route->getGET();
		$this->_post = $this->_route->getPOST();
		$this->_cookie = $this->_route->getCOOKIE();
	}
		  
  public function scrub($field, $type) {
  	if (isset($this->$field)) {
  		$this->$field = Quad_Scrub::clean($this->$field, $type);
  	}
  	return $this;
  }
  
  public function scrubAll($type) {
  	foreach ($this->_data as $field => &$value) {
  		$value = Quad_Scrub::clean($value, $type);
  	}
  	return $this;
  }
  
  public function GET($field, $scrubType = 'general') {
  	return Quad_Scrub::clean($this->$field, $scrubType);
  }
  
  public function POST($field, $scrubType = 'general') {
    if (isset($this->_post[$field])) {
      return Quad_Scrub::clean($this->_post[$field], $scrubType);
      
    } else {
      return null;
    }      	
  }
  
  public function REQUEST($field, $scrubType = 'general') {
    if (isset($this->$field)) {
      $value = $this->$field;
      
    } elseif (isset($this->_post[$field])) {
      $value = $this->_post[$field];
      
    } elseif (isset($this->_cookie[$field])) {
      $value = $this->_cookie[$field];
      
    } else {
      return null;
    }
    return Quad_Scrub::clean($value, $scrubType);   
  }
  
  public function COOKIE($field, $scrubType = 'general') {
    if (isset($this->_cookie[$field])) {
      return Quad_Scrub::clean($this->_cookie[$field], $scrubType);
      
    } else {
      return null;
    }
  }
	
}